package com.itfitness.threaddemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

import com.itfitness.threaddemo.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    private Button btStartThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btStartThread = (Button) findViewById(R.id.bt_start_thread);
        btStartThread.setOnClickListener(v->{
            startThread(new Runnable() {
                @Override
                public void run() {
                    Log.e("JAVA层回调","线程执行");
                    try {
                        Thread.sleep(3000);
                        Log.e("JAVA层回调","线程执行完毕");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        });
    }

    /**
     * 开启线程
     * @return
     */
    public native void startThread(Runnable runnable);
}